


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
  <title>Coverage Report :: CollectionFunction</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
  </style>
</head>

<body>
<div class="header"></div>

<div class="content">
<div class="breadCrumbs">
    [ <a href="../../index.html">all classes</a> ]
    [ <a href="../index.html">at.dormancy.persister.function</a> ]
</div>

<h1>Coverage Summary for Class: CollectionFunction (at.dormancy.persister.function)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">CollectionFunction</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/ 1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (3/ 3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (13/ 13)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<div class="sourceCode"><i>1</i>&nbsp;/*
<i>2</i>&nbsp; * Copyright 2013 Gregor Schauer
<i>3</i>&nbsp; *
<i>4</i>&nbsp; * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<i>5</i>&nbsp; * you may not use this file except in compliance with the License.
<i>6</i>&nbsp; * You may obtain a copy of the License at
<i>7</i>&nbsp; *
<i>8</i>&nbsp; *      http://www.apache.org/licenses/LICENSE-2.0
<i>9</i>&nbsp; *
<i>10</i>&nbsp; * Unless required by applicable law or agreed to in writing, software
<i>11</i>&nbsp; * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<i>12</i>&nbsp; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<i>13</i>&nbsp; * See the License for the specific language governing permissions and
<i>14</i>&nbsp; * limitations under the License.
<i>15</i>&nbsp; */
<i>16</i>&nbsp;package at.dormancy.persister.function;
<i>17</i>&nbsp;
<i>18</i>&nbsp;import org.springframework.core.CollectionFactory;
<i>19</i>&nbsp;
<i>20</i>&nbsp;import javax.annotation.Nonnull;
<i>21</i>&nbsp;import javax.annotation.Nullable;
<i>22</i>&nbsp;import java.util.Collection;
<i>23</i>&nbsp;
<i>24</i>&nbsp;/**
<i>25</i>&nbsp; * Iterates over collections, invoking the provided {@link CollectionFunction} on every element.
<i>26</i>&nbsp; *
<i>27</i>&nbsp; * @author Gregor Schauer
<i>28</i>&nbsp; * @since 1.0.1
<i>29</i>&nbsp; */
<b class="fc"><i>30</i>&nbsp;public class CollectionFunction&lt;E extends Collection&lt;D&gt;, D&gt; extends DelegateFunction&lt;E, D&gt; {</b>
<i>31</i>&nbsp;	@Nullable
<i>32</i>&nbsp;	@Override
<i>33</i>&nbsp;	public FunctionContext&lt;E&gt; apply(@Nullable FunctionContext&lt;E&gt; input) {
<b class="fc"><i>34</i>&nbsp;		if (input == null || input.getObj() == null) {</b>
<b class="fc"><i>35</i>&nbsp;			return input;</b>
<i>36</i>&nbsp;		}
<i>37</i>&nbsp;
<b class="fc"><i>38</i>&nbsp;		E result = createCollection(input.getObj());</b>
<b class="fc"><i>39</i>&nbsp;		FunctionContext&lt;D&gt; elemContext = new FunctionContext&lt;D&gt;(null, input.getTree());</b>
<b class="fc"><i>40</i>&nbsp;		for (D elem : input.getObj()) {</b>
<b class="fc"><i>41</i>&nbsp;			elemContext.setObj(elem);</b>
<b class="fc"><i>42</i>&nbsp;			elemContext = delegate.apply(elemContext);</b>
<b class="fc"><i>43</i>&nbsp;			result.add(elemContext.getObj());</b>
<b class="fc"><i>44</i>&nbsp;		}</b>
<b class="fc"><i>45</i>&nbsp;		input.setObj(result);</b>
<b class="fc"><i>46</i>&nbsp;		return input;</b>
<i>47</i>&nbsp;	}
<i>48</i>&nbsp;
<i>49</i>&nbsp;	/**
<i>50</i>&nbsp;	 * Creates an empty collection of the given type.
<i>51</i>&nbsp;	 *
<i>52</i>&nbsp;	 * @param src the original collection
<i>53</i>&nbsp;	 * @return the new collection
<i>54</i>&nbsp;	 */
<i>55</i>&nbsp;	@Nonnull
<i>56</i>&nbsp;	@SuppressWarnings(&quot;unchecked&quot;)
<i>57</i>&nbsp;	public E createCollection(@Nonnull Collection&lt;?&gt; src) {
<b class="fc"><i>58</i>&nbsp;		return (E) CollectionFactory.createApproximateCollection(src, src.size());</b>
<i>59</i>&nbsp;	}
<i>60</i>&nbsp;}
</div>
</div>

<div class="footer">
    
    <div style="float:right;">generated on 2013-07-31 23:31</div>
</div>
</body>
</html>
